//
//  TopicTableViewController.m
//  NewChat
//
//  Created by lanou3g on 16/2/27.
//  Copyright © 2016年 蓝鸥. All rights reserved.
//

#import "TopicTableViewController.h"
#import "TopicTableViewCell.h"
#import "TopicModel.h"
#import "ClickRightCornerJumpToViewController.h"
#import "MyVoiceViewController.h"
#import "PersonalHomePageTableViewController.h"
#import "ReplyViewController.h"

@interface TopicTableViewController ()<userHeaderDelegate>

@end

@implementation TopicTableViewController

-(instancetype)initWithStyle:(UITableViewStyle)style{
    
    if(self = [super initWithStyle:UITableViewStylePlain]){
        
    }
    return self;
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:YES];
     NSLog(@"这个页面是 社区--> TopicTableViewController");
     self.navigationController.navigationBar.barTintColor = [UIColor greenColor];
    //隐藏底部tabbar
    self.tabBarController.tabBar.hidden = YES;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    

    NSLog(@"这个页面是 社区--> TopicTableViewController");
    //设置右上方按钮
    UIBarButtonItem *BBI1 = [[UIBarButtonItem alloc]initWithTitle:@"🔔" style:(UIBarButtonItemStylePlain) target:self action:@selector(clickRightBarAction1:)];
    
    UIBarButtonItem *BBI2 = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:(UIBarButtonSystemItemCompose) target:self action:@selector(clickRightBarAction2:)];
    
    
    self.navigationItem.rightBarButtonItems = @[BBI1,BBI2];
    
    self.navigationItem.title = self.aString;
    self.view.backgroundColor = [UIColor greenColor];
    [self.tableView registerClass:[TopicTableViewCell class] forCellReuseIdentifier:@"TopCell"];

}

#pragma mark=========UIBarButtonItem的跳转事件======
-(void)clickRightBarAction1:(UIBarButtonItem*)sender{
    NSLog(@"点击编辑跳转");
    ClickRightCornerJumpToViewController *clickRightCornerJumpVC = [[ClickRightCornerJumpToViewController alloc]init];
    
    [self showViewController:clickRightCornerJumpVC sender:nil];
}

-(void)clickRightBarAction2:(UIBarButtonItem*)sender{
    NSLog(@"点击铃铛跳转");
    MyVoiceViewController *myVoiceVC = [[MyVoiceViewController alloc]init];
    
    [self showViewController:myVoiceVC sender:nil];
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

//分区数
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    
    return 5;
}

//每个分区的行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return 1;
}

//区头的高
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    return 10;
}

//cell的高度
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return self.view.frame.size.height/3.8;
     //  return [self tableView:tableView cellForRowAtIndexPath:indexPath].frame.size.height;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    TopicTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TopCell"];
    
    cell.delegate = self;

    if (!cell) {
        cell = [[TopicTableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"TopCell"];
    }
    
    cell.nickNameLbl.text = @"陌生人";
    cell.timeLbl.text = @"1分钟前";
    cell.topicLbl.text = @"你会不会仅仅因为声音就喜欢上对方";
    [cell.messageBtn setTitle:@"100回复" forState:(UIControlStateNormal)];
    [cell.userPictureBtn setBackgroundImage:[UIImage imageNamed:@"55.png"] forState:(UIControlStateNormal)];
    //设置voiceBtn上的文字距离左侧140个像素
    [cell.voiceBtn setTitleEdgeInsets:UIEdgeInsetsMake(0, 140, 0, 0)];
    [cell.voiceBtn setTitle:@"10\"" forState:(UIControlStateNormal)];
    [cell.voiceBtn setTitleColor:[UIColor blackColor] forState:(UIControlStateNormal)];
    
    //传递数据用于子控件赋值（有数据以后实现cell自适应）
    //    TopicModel *model = [[TopicModel alloc]init];
    //
    //    [cell configureCellWithModel:model];
    
    //添加头像点击事件
//    [cell.userPictureBtn addTarget:self action:@selector(noticeTopicViewPushNextView) forControlEvents:(UIControlEventTouchUpInside)];
    
    return cell;
}


//代理方法
-(void)noticeTopicViewPushNextView{

    NSLog(@"代理正在执行跳转到PersonalHomePageTableViewController的方法");
    PersonalHomePageTableViewController*perVC = [[PersonalHomePageTableViewController alloc]init];
    [self.navigationController pushViewController:perVC animated:YES];

}
//cell的点击事件

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    NSLog(@"你点击了TopicTableViewController中的cell");
    
    NSLog(@"即将跳转到的页面是:发现 ——> ReplyViewController");
    ReplyViewController*replyVC = [[ReplyViewController alloc]init];
    replyVC.ControlType = @"topic";
    [self.navigationController pushViewController:replyVC animated:YES];
    
}




/*
 // Override to support conditional editing of the table view.
 - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
 // Return NO if you do not want the specified item to be editable.
 return YES;
 }
 */

/*
 // Override to support editing the table view.
 - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
 if (editingStyle == UITableViewCellEditingStyleDelete) {
 // Delete the row from the data source
 [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
 } else if (editingStyle == UITableViewCellEditingStyleInsert) {
 // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
 }
 }
 */

/*
 // Override to support rearranging the table view.
 - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
 }
 */

/*
 // Override to support conditional rearranging of the table view.
 - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
 // Return NO if you do not want the item to be re-orderable.
 return YES;
 }
 */

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */
@end
